package com.hskj.springboot.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class RabbitMQTTLConfig {
    //定义交换机的名称和队列名称
    public static final String EXCHANGE_NAME = "springboot_ttl_exchange";
    public static final String QUEUE_NAME = "springboot_ttl_queue ";

    /*
    * 配置交换机
    * */
    @Bean("bootTTLExchange")
    public Exchange springboootExchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }
    /*
     * 配置队列
     * */
    @Bean("bootTTLQueue")
    public Queue springbootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).withArgument("x-message-ttl",10000).build();
    }
    /*
    * 绑定交换机和队列
    * */
    @Bean
    public Binding QueueBindingExchange(@Qualifier("bootTTLQueue") Queue queue,@Qualifier("bootTTLExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("ttl.#").noargs();
    }
}
